/*******************************************************************************
 * Copyright (c) 2008, 2025 Lablicate GmbH.
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * Contributors:
 * Philip Wenig - initial API and implementation
 *******************************************************************************/
package org.eclipse.chemclipse.msd.model.implementation;

import static org.junit.Assert.assertEquals;

import org.eclipse.chemclipse.model.signals.ITotalScanSignal;
import org.eclipse.chemclipse.model.signals.ITotalScanSignals;
import org.eclipse.chemclipse.msd.model.core.IIon;
import org.eclipse.chemclipse.msd.model.core.IScanMSD;
import org.eclipse.chemclipse.msd.model.core.selection.ChromatogramSelectionMSD;
import org.eclipse.chemclipse.msd.model.xic.ITotalIonSignalExtractor;
import org.eclipse.chemclipse.msd.model.xic.TotalIonSignalExtractor;
import org.junit.Before;
import org.junit.Test;

/**
 * Add 100 scans and get an {@link ITotalScanSignals} object.
 */
public class Chromatogram_11_Test {

	private ChromatogramMSD chromatogram;
	private ITotalIonSignalExtractor totalIonSignalExtractor;

	@Before
	public void setUp() {

		chromatogram = new ChromatogramMSD();
		// ------------------------------Scan 1-100
		for(int i = 1; i <= 100; i++) {
			IScanMSD supplierMassSpectrum = new ScanMSD();
			supplierMassSpectrum.setRetentionTime(i);
			IIon ion = new Ion(IIon.TIC_ION, i);
			supplierMassSpectrum.addIon(ion);
			chromatogram.addScan(supplierMassSpectrum);
		}
		// ------------------------------Scan 1-100

		totalIonSignalExtractor = new TotalIonSignalExtractor(chromatogram);
	}

	@Test
	public void testGetNumberOfScans_1() {

		assertEquals("numberOfScans", 100, chromatogram.getNumberOfScans());
	}

	@Test
	public void testGetStartRetentionTime_1() {

		assertEquals("startRetentionTime", 1, chromatogram.getStartRetentionTime());
	}

	@Test
	public void testGetStopRetentionTime_1() {

		assertEquals("stopRetentionTime", 100, chromatogram.getStopRetentionTime());
	}

	@Test
	public void testGetTotalIonSignals_1() {

		ChromatogramSelectionMSD chromatogramSelection = new ChromatogramSelectionMSD(chromatogram);
		chromatogramSelection.setStartRetentionTime(20);
		chromatogramSelection.setStopRetentionTime(50);
		ITotalScanSignal signal;
		ITotalScanSignals signals = totalIonSignalExtractor.getTotalIonSignals(chromatogramSelection);
		assertEquals("Size", 31, signals.size());
		assertEquals("startScan", 20, signals.getStartScan());
		assertEquals("startScan", 50, signals.getStopScan());
		signal = signals.getTotalScanSignal(20);
		assertEquals("Scan", 20, signal.getRetentionTime());
		signal = signals.getTotalScanSignal(50);
		assertEquals("Scan", 50, signal.getRetentionTime());
	}
}
